<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionView::Helpers::PrototypeHelper</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionView::Helpers::PrototypeHelper</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/rails/actionpack/lib/action_view/helpers/prototype_helper_rb.html">
                vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
<a href="http://www.prototypejs.org/">Prototype</a> is a JavaScript library
that provides <a
href="http://en.wikipedia.org/wiki/Document_Object_Model">DOM</a>
manipulation, <a
href="http://www.adaptivepath.com/publications/essays/archives/000385.php">Ajax</a>
functionality, and more traditional object-oriented facilities for
JavaScript. This module provides a set of helpers to make it more
convenient to call functions from Prototype using <a
href="../../Rails.html">Rails</a>, including functionality to call remote
<a href="../../Rails.html">Rails</a> methods (that is, making a background
request to a <a href="../../Rails.html">Rails</a> action) using Ajax. This
means that you can call actions in your controllers without reloading the
page, but still update certain parts of it using injections into the DOM. A
common use case is having a form that adds a new element to a list without
reloading the page or updating a shopping cart total when a new item is
added.
</p>
<h2>Usage</h2>
<p>
To be able to use these helpers, you must first include the Prototype
JavaScript framework in your pages.
</p>
<pre>
 javascript_include_tag 'prototype'
</pre>
<p>
(See the documentation for <a
href="JavaScriptHelper.html">ActionView::Helpers::JavaScriptHelper</a> for
more information on including this and other JavaScript files in your <a
href="../../Rails.html">Rails</a> templates.)
</p>
<p>
Now you&#8216;re ready to call a remote action either through a link&#8230;
</p>
<pre>
 link_to_remote &quot;Add to cart&quot;,
   :url =&gt; { :action =&gt; &quot;add&quot;, :id =&gt; product.id },
   :update =&gt; { :success =&gt; &quot;cart&quot;, :failure =&gt; &quot;error&quot; }
</pre>
<p>
&#8230;through a form&#8230;
</p>
<pre>
 &lt;% form_remote_tag :url =&gt; '/shipping' do -%&gt;
   &lt;div&gt;&lt;%= submit_tag 'Recalculate Shipping' %&gt;&lt;/div&gt;
 &lt;% end -%&gt;
</pre>
<p>
&#8230;periodically&#8230;
</p>
<pre>
 periodically_call_remote(:url =&gt; 'update', :frequency =&gt; '5', :update =&gt; 'ticker')
</pre>
<p>
&#8230;or through an observer (i.e., a form or field that is observed and
calls a remote action when changed).
</p>
<pre>
 &lt;%= observe_field(:searchbox,
      :url =&gt; { :action =&gt; :live_search }),
      :frequency =&gt; 0.5,
      :update =&gt; :hits,
      :with =&gt; 'query'
      %&gt;
</pre>
<p>
As you can see, there are numerous ways to use Prototype&#8216;s Ajax
functions (and actually more than are listed here); check out the
documentation for each method to find out more about its usage and options.
</p>
<h3>Common Options</h3>
<p>
See <a href="PrototypeHelper.html#M000958">link_to_remote</a> for
documentation of options common to all Ajax helpers; any of the options
specified by <a href="PrototypeHelper.html#M000958">link_to_remote</a> can
be used by the other helpers.
</p>
<h2>Designing your <a href="../../Rails.html">Rails</a> actions for Ajax</h2>
<p>
When building your action handlers (that is, the <a
href="../../Rails.html">Rails</a> actions that receive your background
requests), it&#8216;s important to remember a few things. First, whatever
your action would normall return to the browser, it will return to the Ajax
call. As such, you typically don&#8216;t want to render with a layout. This
call will cause the layout to be transmitted back to your page, and, if you
have a full HTML/CSS, will likely mess a lot of things up. You can turn the
layout off on particular actions by doing the following:
</p>
<pre>
 class SiteController &lt; ActionController::Base
   layout &quot;standard&quot;, :except =&gt; [:ajax_method, :more_ajax, :another_ajax]
 end
</pre>
<p>
Optionally, you could do this in the method you wish to lack a layout:
</p>
<pre>
 render :layout =&gt; false
</pre>
<p>
You can tell the type of request from within your action using the
<tt>request.xhr?</tt> (XmlHttpRequest, the method that Ajax uses to make
background requests) method.
</p>
<pre>
 def name
   # Is this an XmlHttpRequest request?
   if (request.xhr?)
     render :text =&gt; @name.to_s
   else
     # No?  Then render an action.
     render :action =&gt; 'view_attribute', :attr =&gt; @name
   end
 end
</pre>
<p>
The else clause can be left off and the current action will render with
full layout and template. An extension to this solution was posted to Ryan
Heneise&#8216;s blog at <a
href=""http://www.artofmission.com/"">ArtOfMission</a>.
</p>
<pre>
 layout proc{ |c| c.request.xhr? ? false : &quot;application&quot; }
</pre>
<p>
Dropping this in your ApplicationController turns the layout off for every
request that is an &quot;xhr&quot; request.
</p>
<p>
If you are just returning a little data or don&#8216;t want to build a
template for your output, you may opt to simply render text output, like
this:
</p>
<pre>
 render :text =&gt; 'Return this from my method!'
</pre>
<p>
Since whatever the method returns is injected into the DOM, this will
simply inject some text (or HTML, if you tell it to). This is usually how
small updates, such updating a cart total or a file count, are handled.
</p>
<h2>Updating multiple elements</h2>
<p>
See JavaScriptGenerator for information on updating multiple elements on
the page in an Ajax response.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000973">build_callbacks</a>&nbsp;&nbsp;
      <a href="#M000972">build_observer</a>&nbsp;&nbsp;
      <a href="#M000964">evaluate_remote_response</a>&nbsp;&nbsp;
      <a href="#M000962">form_remote_for</a>&nbsp;&nbsp;
      <a href="#M000960">form_remote_tag</a>&nbsp;&nbsp;
      <a href="#M000958">link_to_remote</a>&nbsp;&nbsp;
      <a href="#M000971">method_option_to_s</a>&nbsp;&nbsp;
      <a href="#M000966">observe_field</a>&nbsp;&nbsp;
      <a href="#M000967">observe_form</a>&nbsp;&nbsp;
      <a href="#M000970">options_for_ajax</a>&nbsp;&nbsp;
      <a href="#M000959">periodically_call_remote</a>&nbsp;&nbsp;
      <a href="#M000961">remote_form_for</a>&nbsp;&nbsp;
      <a href="#M000965">remote_function</a>&nbsp;&nbsp;
      <a href="#M000963">submit_to_remote</a>&nbsp;&nbsp;
      <a href="#M000968">update_page</a>&nbsp;&nbsp;
      <a href="#M000969">update_page_tag</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">CALLBACKS</td>
          <td>=</td>
          <td class="context-item-value">Set.new([ :uninitialized, :loading, :loaded,                          :interactive, :complete, :failure, :success ] +                          (100..599).to_a)</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">AJAX_OPTIONS</td>
          <td>=</td>
          <td class="context-item-value">Set.new([ :before, :after, :condition, :url,                          :asynchronous, :method, :insertion, :position,                          :form, :with, :update, :script ]).merge(CALLBACKS)</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000964" class="method-detail">
        <a name="M000964"></a>

        <div class="method-heading">
          <a href="#M000964" class="method-signature">
          <span class="method-name">evaluate_remote_response</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns &#8216;<tt>eval(request.responseText)</tt>&#8217; which is the
JavaScript function that <a
href="PrototypeHelper.html#M000960">form_remote_tag</a> can call in
:complete to evaluate a multiple update return document using
update_element_function calls.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000964-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000964-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 427</span>
427:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">evaluate_remote_response</span>
428:         <span class="ruby-value str">&quot;eval(request.responseText)&quot;</span>
429:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000962" class="method-detail">
        <a name="M000962"></a>

        <div class="method-heading">
          <span class="method-name">form_remote_for</span><span class="method-args">(record_or_name_or_array, *args, &amp;proc)</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="PrototypeHelper.html#M000961">remote_form_for</a>
</p>
        </div>
      </div>

      <div id="method-M000960" class="method-detail">
        <a name="M000960"></a>

        <div class="method-heading">
          <a href="#M000960" class="method-signature">
          <span class="method-name">form_remote_tag</span><span class="method-args">(options = {}, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a form tag that will submit using XMLHttpRequest in the background
instead of the regular reloading POST arrangement. Even though it&#8216;s
using JavaScript to serialize the form elements, the form submission will
work just like a regular submission as viewed by the receiving side (all
elements available in <tt>params</tt>). The options for specifying the
target with :url and defining callbacks is the same as <a
href="PrototypeHelper.html#M000958">link_to_remote</a>.
</p>
<p>
A &quot;fall-through&quot; target for browsers that doesn&#8216;t do
JavaScript can be specified with the :action/:method options on :html.
</p>
<p>
Example:
</p>
<pre>
  # Generates:
  #      &lt;form action=&quot;/some/place&quot; method=&quot;post&quot; onsubmit=&quot;new Ajax.Request('',
  #      {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;&quot;&gt;
  form_remote_tag :html =&gt; { :action =&gt;
    url_for(:controller =&gt; &quot;some&quot;, :action =&gt; &quot;place&quot;) }
</pre>
<p>
The Hash passed to the :html key is equivalent to the options (2nd)
argument in the <a
href="FormTagHelper.html#M001036">FormTagHelper.form_tag</a> method.
</p>
<p>
By default the fall-through action is the same as the one specified in the
:url (and the default method is :post).
</p>
<p>
<a href="PrototypeHelper.html#M000960">form_remote_tag</a> also takes a
block, like form_tag:
</p>
<pre>
  # Generates:
  #     &lt;form action=&quot;/&quot; method=&quot;post&quot; onsubmit=&quot;new Ajax.Request('/',
  #     {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)});
  #     return false;&quot;&gt; &lt;div&gt;&lt;input name=&quot;commit&quot; type=&quot;submit&quot; value=&quot;Save&quot; /&gt;&lt;/div&gt;
  #     &lt;/form&gt;
  &lt;% form_remote_tag :url =&gt; '/posts' do -%&gt;
    &lt;div&gt;&lt;%= submit_tag 'Save' %&gt;&lt;/div&gt;
  &lt;% end -%&gt;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000960-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000960-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 322</span>
322:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">form_remote_tag</span>(<span class="ruby-identifier">options</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
323:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:form</span>] = <span class="ruby-keyword kw">true</span>
324: 
325:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:html</span>] <span class="ruby-operator">||=</span> {}
326:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:html</span>][<span class="ruby-identifier">:onsubmit</span>] = 
327:           (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:html</span>][<span class="ruby-identifier">:onsubmit</span>] <span class="ruby-operator">?</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:html</span>][<span class="ruby-identifier">:onsubmit</span>] <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;; &quot;</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot;&quot;</span>) <span class="ruby-operator">+</span> 
328:           <span class="ruby-node">&quot;#{remote_function(options)}; return false;&quot;</span>
329: 
330:         <span class="ruby-identifier">form_tag</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:html</span>].<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:action</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">url_for</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:url</span>]), <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:html</span>], <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
331:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000958" class="method-detail">
        <a name="M000958"></a>

        <div class="method-heading">
          <a href="#M000958" class="method-signature">
          <span class="method-name">link_to_remote</span><span class="method-args">(name, options = {}, html_options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a link to a remote action defined by <tt>options[:url]</tt> (using
the url_for format) that&#8216;s called in the background using
XMLHttpRequest. The result of that request can then be inserted into a DOM
object whose id can be specified with <tt>options[:update]</tt>. Usually,
the result would be a partial prepared by the controller with render
:partial.
</p>
<p>
Examples:
</p>
<pre>
  # Generates: &lt;a href=&quot;#&quot; onclick=&quot;new Ajax.Updater('posts', '/blog/destroy/3', {asynchronous:true, evalScripts:true});
  #            return false;&quot;&gt;Delete this post&lt;/a&gt;
  link_to_remote &quot;Delete this post&quot;, :update =&gt; &quot;posts&quot;,
    :url =&gt; { :action =&gt; &quot;destroy&quot;, :id =&gt; post.id }

  # Generates: &lt;a href=&quot;#&quot; onclick=&quot;new Ajax.Updater('emails', '/mail/list_emails', {asynchronous:true, evalScripts:true});
  #            return false;&quot;&gt;&lt;img alt=&quot;Refresh&quot; src=&quot;/images/refresh.png?&quot; /&gt;&lt;/a&gt;
  link_to_remote(image_tag(&quot;refresh&quot;), :update =&gt; &quot;emails&quot;,
    :url =&gt; { :action =&gt; &quot;list_emails&quot; })
</pre>
<p>
You can override the generated HTML options by specifying a hash in
<tt>options[:html]</tt>.
</p>
<pre>
  link_to_remote &quot;Delete this post&quot;, :update =&gt; &quot;posts&quot;,
    :url  =&gt; post_url(@post), :method =&gt; :delete,
    :html =&gt; { :class  =&gt; &quot;destructive&quot; }
</pre>
<p>
You can also specify a hash for <tt>options[:update]</tt> to allow for easy
redirection of output to an other DOM element if a server-side error
occurs:
</p>
<p>
Example:
</p>
<pre>
  # Generates: &lt;a href=&quot;#&quot; onclick=&quot;new Ajax.Updater({success:'posts',failure:'error'}, '/blog/destroy/5',
  #            {asynchronous:true, evalScripts:true}); return false;&quot;&gt;Delete this post&lt;/a&gt;
  link_to_remote &quot;Delete this post&quot;,
    :url =&gt; { :action =&gt; &quot;destroy&quot;, :id =&gt; post.id },
    :update =&gt; { :success =&gt; &quot;posts&quot;, :failure =&gt; &quot;error&quot; }
</pre>
<p>
Optionally, you can use the <tt>options[:position]</tt> parameter to
influence how the target DOM element is updated. It must be one of
<tt>:before</tt>, <tt>:top</tt>, <tt>:bottom</tt>, or <tt>:after</tt>.
</p>
<p>
The method used is by default POST. You can also specify GET or you can
simulate PUT or DELETE over POST. All specified with
<tt>options[:method]</tt>
</p>
<p>
Example:
</p>
<pre>
  # Generates: &lt;a href=&quot;#&quot; onclick=&quot;new Ajax.Request('/person/4', {asynchronous:true, evalScripts:true, method:'delete'});
  #            return false;&quot;&gt;Destroy&lt;/a&gt;
  link_to_remote &quot;Destroy&quot;, :url =&gt; person_url(:id =&gt; person), :method =&gt; :delete
</pre>
<p>
By default, these remote requests are processed asynchronous during which
various JavaScript callbacks can be triggered (for progress indicators and
the likes). All callbacks get access to the <tt>request</tt> object, which
holds the underlying XMLHttpRequest.
</p>
<p>
To access the server response, use <tt>request.responseText</tt>, to find
out the HTTP status, use <tt>request.status</tt>.
</p>
<p>
Example:
</p>
<pre>
  # Generates: &lt;a href=&quot;#&quot; onclick=&quot;new Ajax.Request('/words/undo?n=33', {asynchronous:true, evalScripts:true,
  #            onComplete:function(request){undoRequestCompleted(request)}}); return false;&quot;&gt;hello&lt;/a&gt;
  word = 'hello'
  link_to_remote word,
    :url =&gt; { :action =&gt; &quot;undo&quot;, :n =&gt; word_counter },
    :complete =&gt; &quot;undoRequestCompleted(request)&quot;
</pre>
<p>
The callbacks that may be specified are (in order):
</p>
<table>
<tr><td valign="top"><tt>:loading</tt>:</td><td>Called when the remote document is being loaded with data by the browser.

</td></tr>
<tr><td valign="top"><tt>:loaded</tt>:</td><td>Called when the browser has finished loading the remote document.

</td></tr>
<tr><td valign="top"><tt>:interactive</tt>:</td><td>Called when the user can interact with the remote document, even though it
has not finished loading.

</td></tr>
<tr><td valign="top"><tt>:success</tt>:</td><td>Called when the XMLHttpRequest is completed, and the HTTP status code is in
the 2XX range.

</td></tr>
<tr><td valign="top"><tt>:failure</tt>:</td><td>Called when the XMLHttpRequest is completed, and the HTTP status code is
not in the 2XX range.

</td></tr>
<tr><td valign="top"><tt>:complete</tt>:</td><td>Called when the XMLHttpRequest is complete (fires after success/failure if
they are present).

</td></tr>
</table>
<p>
You can further refine <tt>:success</tt> and <tt>:failure</tt> by adding
additional callbacks for specific status codes.
</p>
<p>
Example:
</p>
<pre>
  # Generates: &lt;a href=&quot;#&quot; onclick=&quot;new Ajax.Request('/testing/action', {asynchronous:true, evalScripts:true,
  #            on404:function(request){alert('Not found...? Wrong URL...?')},
  #            onFailure:function(request){alert('HTTP Error ' + request.status + '!')}}); return false;&quot;&gt;hello&lt;/a&gt;
  link_to_remote word,
    :url =&gt; { :action =&gt; &quot;action&quot; },
    404 =&gt; &quot;alert('Not found...? Wrong URL...?')&quot;,
    :failure =&gt; &quot;alert('HTTP Error ' + request.status + '!')&quot;
</pre>
<p>
A status code callback overrides the success/failure handlers if present.
</p>
<p>
If you for some reason or another need synchronous processing
(that&#8216;ll block the browser while the request is happening), you can
specify <tt>options[:type] = :synchronous</tt>.
</p>
<p>
You can customize further browser side call logic by passing in JavaScript
code snippets via some optional parameters. In their order of use these
are:
</p>
<table>
<tr><td valign="top"><tt>:confirm</tt>:</td><td>Adds confirmation dialog.

</td></tr>
<tr><td valign="top"><tt>:condition</tt>:</td><td>Perform remote request conditionally by this expression. Use this to
describe browser-side conditions when request should not be initiated.

</td></tr>
<tr><td valign="top"><tt>:before</tt>:</td><td>Called before request is initiated.

</td></tr>
<tr><td valign="top"><tt>:after</tt>:</td><td>Called immediately after request was initiated and before
<tt>:loading</tt>.

</td></tr>
<tr><td valign="top"><tt>:submit</tt>:</td><td>Specifies the DOM element ID that&#8216;s used as the parent of the form
elements. By default this is the current form, but it could just as well be
the ID of a table row or any other DOM element.

</td></tr>
<tr><td valign="top"><tt>:with</tt>:</td><td>A JavaScript expression specifying the parameters for the XMLHttpRequest.
Any expressions should return a valid URL query string.

<p>
Example:
</p>
<pre>
  :with =&gt; &quot;'name=' + $('name').value&quot;
</pre>
</td></tr>
</table>
<p>
You can generate a link that uses AJAX in the general case, while degrading
gracefully to plain link behavior in the absence of JavaScript by setting
<tt>html_options[:href]</tt> to an alternate URL. Note the extra curly
braces around the <tt>options</tt> hash separate it as the second parameter
from <tt>html_options</tt>, the third.
</p>
<p>
Example:
</p>
<pre>
  link_to_remote &quot;Delete this post&quot;,
    { :update =&gt; &quot;posts&quot;, :url =&gt; { :action =&gt; &quot;destroy&quot;, :id =&gt; post.id } },
    :href =&gt; url_for(:action =&gt; &quot;destroy&quot;, :id =&gt; post.id)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000958-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000958-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 254</span>
254:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">link_to_remote</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = <span class="ruby-keyword kw">nil</span>)  
255:         <span class="ruby-identifier">link_to_function</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">remote_function</span>(<span class="ruby-identifier">options</span>), <span class="ruby-identifier">html_options</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:html</span>))
256:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000966" class="method-detail">
        <a name="M000966"></a>

        <div class="method-heading">
          <a href="#M000966" class="method-signature">
          <span class="method-name">observe_field</span><span class="method-args">(field_id, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Observes the field with the DOM ID specified by <tt>field_id</tt> and calls
a callback when its contents have changed. The default callback is an Ajax
call. By default the value of the observed field is sent as a parameter
with the Ajax call.
</p>
<p>
Example:
</p>
<pre>
 # Generates: new Form.Element.Observer('suggest', 0.25, function(element, value) {new Ajax.Updater('suggest',
 #         '/testing/find_suggestion', {asynchronous:true, evalScripts:true, parameters:'q=' + value})})
 &lt;%= observe_field :suggest, :url =&gt; { :action =&gt; :find_suggestion },
      :frequency =&gt; 0.25,
      :update =&gt; :suggest,
      :with =&gt; 'q'
      %&gt;
</pre>
<p>
Required <tt>options</tt> are either of:
</p>
<table>
<tr><td valign="top"><tt>:url</tt>:</td><td><tt>url_for</tt>-style options for the action to call when the field has
changed.

</td></tr>
<tr><td valign="top"><tt>:function</tt>:</td><td>Instead of making a remote call to a URL, you can specify javascript code
to be called instead. Note that the value of this option is used as the
<b>body</b> of the javascript function, a function definition with
parameters named element and value will be generated for you for example:

<pre>
  observe_field(&quot;glass&quot;, :frequency =&gt; 1, :function =&gt; &quot;alert('Element changed')&quot;)
</pre>
<p>
will generate:
</p>
<pre>
  new Form.Element.Observer('glass', 1, function(element, value) {alert('Element changed')})
</pre>
<p>
The element parameter is the DOM element being observed, and the value is
its value at the time the observer is triggered.
</p>
</td></tr>
</table>
<p>
Additional options are:
</p>
<table>
<tr><td valign="top"><tt>:frequency</tt>:</td><td>The frequency (in seconds) at which changes to this field will be detected.
Not setting this option at all or to a value equal to or less than zero
will use event based observation instead of time based observation.

</td></tr>
<tr><td valign="top"><tt>:update</tt>:</td><td>Specifies the DOM ID of the element whose innerHTML should be updated with
the XMLHttpRequest response text.

</td></tr>
<tr><td valign="top"><tt>:with</tt>:</td><td>A JavaScript expression specifying the parameters for the XMLHttpRequest.
The default is to send the key and value of the observed field. Any custom
expressions should return a valid URL query string. The value of the field
is stored in the JavaScript variable <tt>value</tt>.

<p>
Examples
</p>
<pre>
  :with =&gt; &quot;'my_custom_key=' + value&quot;
  :with =&gt; &quot;'person[name]=' + prompt('New name')&quot;
  :with =&gt; &quot;Form.Element.serialize('other-field')&quot;
</pre>
<p>
Finally
</p>
<pre>
  :with =&gt; 'name'
</pre>
<p>
is shorthand for
</p>
<pre>
  :with =&gt; &quot;'name=' + value&quot;
</pre>
<p>
This essentially just changes the key of the parameter.
</p>
</td></tr>
<tr><td valign="top"><tt>:on</tt>:</td><td>Specifies which event handler to observe. By default, it&#8216;s set to
&quot;changed&quot; for text fields and areas and &quot;click&quot; for
radio buttons and checkboxes. With this, you can specify it instead to be
&quot;blur&quot; or &quot;focus&quot; or any other event.

</td></tr>
</table>
<p>
Additionally, you may specify any of the options documented in the
<em>Common options</em> section at the top of this document.
</p>
<p>
Example:
</p>
<pre>
  # Sends params: {:title =&gt; 'Title of the book'} when the book_title input
  # field is changed.
  observe_field 'book_title',
    :url =&gt; 'http://example.com/books/edit/1',
    :with =&gt; 'title'

  # Sends params: {:book_title =&gt; 'Title of the book'} when the focus leaves
  # the input field.
  observe_field 'book_title',
    :url =&gt; 'http://example.com/books/edit/1',
    :on =&gt; 'blur'
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000966-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000966-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 551</span>
551:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">observe_field</span>(<span class="ruby-identifier">field_id</span>, <span class="ruby-identifier">options</span> = {})
552:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:frequency</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:frequency</span>] <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
553:           <span class="ruby-identifier">build_observer</span>(<span class="ruby-value str">'Form.Element.Observer'</span>, <span class="ruby-identifier">field_id</span>, <span class="ruby-identifier">options</span>)
554:         <span class="ruby-keyword kw">else</span>
555:           <span class="ruby-identifier">build_observer</span>(<span class="ruby-value str">'Form.Element.EventObserver'</span>, <span class="ruby-identifier">field_id</span>, <span class="ruby-identifier">options</span>)
556:         <span class="ruby-keyword kw">end</span>
557:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000967" class="method-detail">
        <a name="M000967"></a>

        <div class="method-heading">
          <a href="#M000967" class="method-signature">
          <span class="method-name">observe_form</span><span class="method-args">(form_id, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Observes the form with the DOM ID specified by <tt>form_id</tt> and calls a
callback when its contents have changed. The default callback is an Ajax
call. By default all fields of the observed field are sent as parameters
with the Ajax call.
</p>
<p>
The <tt>options</tt> for <tt><a
href="PrototypeHelper.html#M000967">observe_form</a></tt> are the same as
the options for <tt><a
href="PrototypeHelper.html#M000966">observe_field</a></tt>. The JavaScript
variable <tt>value</tt> available to the <tt>:with</tt> option is set to
the serialized form by default.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000967-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000967-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 567</span>
567:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">observe_form</span>(<span class="ruby-identifier">form_id</span>, <span class="ruby-identifier">options</span> = {})
568:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:frequency</span>]
569:           <span class="ruby-identifier">build_observer</span>(<span class="ruby-value str">'Form.Observer'</span>, <span class="ruby-identifier">form_id</span>, <span class="ruby-identifier">options</span>)
570:         <span class="ruby-keyword kw">else</span>
571:           <span class="ruby-identifier">build_observer</span>(<span class="ruby-value str">'Form.EventObserver'</span>, <span class="ruby-identifier">form_id</span>, <span class="ruby-identifier">options</span>)
572:         <span class="ruby-keyword kw">end</span>
573:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000959" class="method-detail">
        <a name="M000959"></a>

        <div class="method-heading">
          <a href="#M000959" class="method-signature">
          <span class="method-name">periodically_call_remote</span><span class="method-args">(options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Periodically calls the specified url (<tt>options[:url]</tt>) every
<tt>options[:frequency]</tt> seconds (default is 10). Usually used to
update a specified div (<tt>options[:update]</tt>) with the results of the
remote call. The options for specifying the target with :url and defining
callbacks is the same as <a
href="PrototypeHelper.html#M000958">link_to_remote</a>. Examples:
</p>
<pre>
 # Call get_averages and put its results in 'avg' every 10 seconds
 # Generates:
 #      new PeriodicalExecuter(function() {new Ajax.Updater('avg', '/grades/get_averages',
 #      {asynchronous:true, evalScripts:true})}, 10)
 periodically_call_remote(:url =&gt; { :action =&gt; 'get_averages' }, :update =&gt; 'avg')

 # Call invoice every 10 seconds with the id of the customer
 # If it succeeds, update the invoice DIV; if it fails, update the error DIV
 # Generates:
 #      new PeriodicalExecuter(function() {new Ajax.Updater({success:'invoice',failure:'error'},
 #      '/testing/invoice/16', {asynchronous:true, evalScripts:true})}, 10)
 periodically_call_remote(:url =&gt; { :action =&gt; 'invoice', :id =&gt; customer.id },
    :update =&gt; { :success =&gt; &quot;invoice&quot;, :failure =&gt; &quot;error&quot; }

 # Call update every 20 seconds and update the new_block DIV
 # Generates:
 # new PeriodicalExecuter(function() {new Ajax.Updater('news_block', 'update', {asynchronous:true, evalScripts:true})}, 20)
 periodically_call_remote(:url =&gt; 'update', :frequency =&gt; '20', :update =&gt; 'news_block')
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000959-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000959-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 283</span>
283:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">periodically_call_remote</span>(<span class="ruby-identifier">options</span> = {})
284:          <span class="ruby-identifier">frequency</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:frequency</span>] <span class="ruby-operator">||</span> <span class="ruby-value">10</span> <span class="ruby-comment cmt"># every ten seconds by default</span>
285:          <span class="ruby-identifier">code</span> = <span class="ruby-node">&quot;new PeriodicalExecuter(function() {#{remote_function(options)}}, #{frequency})&quot;</span>
286:          <span class="ruby-identifier">javascript_tag</span>(<span class="ruby-identifier">code</span>)
287:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000961" class="method-detail">
        <a name="M000961"></a>

        <div class="method-heading">
          <a href="#M000961" class="method-signature">
          <span class="method-name">remote_form_for</span><span class="method-args">(record_or_name_or_array, *args, &amp;proc)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a form that will submit using XMLHttpRequest in the background
instead of the regular reloading POST arrangement and a scope around a
specific resource that is used as a base for questioning about values for
the fields.
</p>
<h3>Resource</h3>
<p>
Example:
</p>
<pre>
  &lt;% remote_form_for(@post) do |f| %&gt;
    ...
  &lt;% end %&gt;
</pre>
<p>
This will expand to be the same as:
</p>
<pre>
  &lt;% remote_form_for :post, @post, :url =&gt; post_path(@post), :html =&gt; { :method =&gt; :put, :class =&gt; &quot;edit_post&quot;, :id =&gt; &quot;edit_post_45&quot; } do |f| %&gt;
    ...
  &lt;% end %&gt;
</pre>
<h3>Nested Resource</h3>
<p>
Example:
</p>
<pre>
  &lt;% remote_form_for([@post, @comment]) do |f| %&gt;
    ...
  &lt;% end %&gt;
</pre>
<p>
This will expand to be the same as:
</p>
<pre>
  &lt;% remote_form_for :comment, @comment, :url =&gt; post_comment_path(@post, @comment), :html =&gt; { :method =&gt; :put, :class =&gt; &quot;edit_comment&quot;, :id =&gt; &quot;edit_comment_45&quot; } do |f| %&gt;
    ...
  &lt;% end %&gt;
</pre>
<p>
If you don&#8216;t need to attach a form to a resource, then check out <a
href="PrototypeHelper.html#M000960">form_remote_tag</a>.
</p>
<p>
See <a href="FormHelper.html#M000920">FormHelper#form_for</a> for
additional semantics.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000961-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000961-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 367</span>
367:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remote_form_for</span>(<span class="ruby-identifier">record_or_name_or_array</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">proc</span>)
368:         <span class="ruby-identifier">options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>
369: 
370:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">record_or_name_or_array</span>
371:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>, <span class="ruby-constant">Symbol</span>
372:           <span class="ruby-identifier">object_name</span> = <span class="ruby-identifier">record_or_name_or_array</span>
373:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Array</span>
374:           <span class="ruby-identifier">object</span> = <span class="ruby-identifier">record_or_name_or_array</span>.<span class="ruby-identifier">last</span>
375:           <span class="ruby-identifier">object_name</span> = <span class="ruby-constant">ActionController</span><span class="ruby-operator">::</span><span class="ruby-constant">RecordIdentifier</span>.<span class="ruby-identifier">singular_class_name</span>(<span class="ruby-identifier">object</span>)
376:           <span class="ruby-identifier">apply_form_for_options!</span>(<span class="ruby-identifier">record_or_name_or_array</span>, <span class="ruby-identifier">options</span>)
377:           <span class="ruby-identifier">args</span>.<span class="ruby-identifier">unshift</span> <span class="ruby-identifier">object</span>
378:         <span class="ruby-keyword kw">else</span>
379:           <span class="ruby-identifier">object</span>      = <span class="ruby-identifier">record_or_name_or_array</span>
380:           <span class="ruby-identifier">object_name</span> = <span class="ruby-constant">ActionController</span><span class="ruby-operator">::</span><span class="ruby-constant">RecordIdentifier</span>.<span class="ruby-identifier">singular_class_name</span>(<span class="ruby-identifier">record_or_name_or_array</span>)
381:           <span class="ruby-identifier">apply_form_for_options!</span>(<span class="ruby-identifier">object</span>, <span class="ruby-identifier">options</span>)
382:           <span class="ruby-identifier">args</span>.<span class="ruby-identifier">unshift</span> <span class="ruby-identifier">object</span>
383:         <span class="ruby-keyword kw">end</span>
384: 
385:         <span class="ruby-identifier">concat</span>(<span class="ruby-identifier">form_remote_tag</span>(<span class="ruby-identifier">options</span>), <span class="ruby-identifier">proc</span>.<span class="ruby-identifier">binding</span>)
386:         <span class="ruby-identifier">fields_for</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-operator">*</span>(<span class="ruby-identifier">args</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">options</span>), <span class="ruby-operator">&amp;</span><span class="ruby-identifier">proc</span>)
387:         <span class="ruby-identifier">concat</span>(<span class="ruby-value str">'&lt;/form&gt;'</span>, <span class="ruby-identifier">proc</span>.<span class="ruby-identifier">binding</span>)
388:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000965" class="method-detail">
        <a name="M000965"></a>

        <div class="method-heading">
          <a href="#M000965" class="method-signature">
          <span class="method-name">remote_function</span><span class="method-args">(options)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the JavaScript needed for a remote function. Takes the same
arguments as <a href="PrototypeHelper.html#M000958">link_to_remote</a>.
</p>
<p>
Example:
</p>
<pre>
  # Generates: &lt;select id=&quot;options&quot; onchange=&quot;new Ajax.Updater('options',
  # '/testing/update_options', {asynchronous:true, evalScripts:true})&quot;&gt;
  &lt;select id=&quot;options&quot; onchange=&quot;&lt;%= remote_function(:update =&gt; &quot;options&quot;,
      :url =&gt; { :action =&gt; :update_options }) %&gt;&quot;&gt;
    &lt;option value=&quot;0&quot;&gt;Hello&lt;/option&gt;
    &lt;option value=&quot;1&quot;&gt;World&lt;/option&gt;
  &lt;/select&gt;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000965-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000965-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 442</span>
442:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remote_function</span>(<span class="ruby-identifier">options</span>)
443:         <span class="ruby-identifier">javascript_options</span> = <span class="ruby-identifier">options_for_ajax</span>(<span class="ruby-identifier">options</span>)
444: 
445:         <span class="ruby-identifier">update</span> = <span class="ruby-value str">''</span>
446:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:update</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:update</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
447:           <span class="ruby-identifier">update</span>  = []
448:           <span class="ruby-identifier">update</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;success:'#{options[:update][:success]}'&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:update</span>][<span class="ruby-identifier">:success</span>]
449:           <span class="ruby-identifier">update</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;failure:'#{options[:update][:failure]}'&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:update</span>][<span class="ruby-identifier">:failure</span>]
450:           <span class="ruby-identifier">update</span>  = <span class="ruby-value str">'{'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">update</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">','</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">'}'</span>
451:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:update</span>]
452:           <span class="ruby-identifier">update</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;'#{options[:update]}'&quot;</span>
453:         <span class="ruby-keyword kw">end</span>
454: 
455:         <span class="ruby-identifier">function</span> = <span class="ruby-identifier">update</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-value">? </span>
456:           <span class="ruby-value str">&quot;new Ajax.Request(&quot;</span> <span class="ruby-operator">:</span>
457:           <span class="ruby-node">&quot;new Ajax.Updater(#{update}, &quot;</span>
458: 
459:         <span class="ruby-identifier">url_options</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:url</span>]
460:         <span class="ruby-identifier">url_options</span> = <span class="ruby-identifier">url_options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">:escape</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">url_options</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
461:         <span class="ruby-identifier">function</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;'#{url_for(url_options)}'&quot;</span>
462:         <span class="ruby-identifier">function</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;, #{javascript_options})&quot;</span>
463: 
464:         <span class="ruby-identifier">function</span> = <span class="ruby-node">&quot;#{options[:before]}; #{function}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:before</span>]
465:         <span class="ruby-identifier">function</span> = <span class="ruby-node">&quot;#{function}; #{options[:after]}&quot;</span>  <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:after</span>]
466:         <span class="ruby-identifier">function</span> = <span class="ruby-node">&quot;if (#{options[:condition]}) { #{function}; }&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:condition</span>]
467:         <span class="ruby-identifier">function</span> = <span class="ruby-node">&quot;if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:confirm</span>]
468: 
469:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">function</span>
470:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000963" class="method-detail">
        <a name="M000963"></a>

        <div class="method-heading">
          <a href="#M000963" class="method-signature">
          <span class="method-name">submit_to_remote</span><span class="method-args">(name, value, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a button input tag with the element name of <tt>name</tt> and a
value (i.e., display text) of <tt>value</tt> that will submit form using
XMLHttpRequest in the background instead of a regular POST request that
reloads the page.
</p>
<pre>
 # Create a button that submits to the create action
 #
 # Generates: &lt;input name=&quot;create_btn&quot; onclick=&quot;new Ajax.Request('/testing/create',
 #     {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)});
 #     return false;&quot; type=&quot;button&quot; value=&quot;Create&quot; /&gt;
 &lt;%= submit_to_remote 'create_btn', 'Create', :url =&gt; { :action =&gt; 'create' } %&gt;

 # Submit to the remote action update and update the DIV succeed or fail based
 # on the success or failure of the request
 #
 # Generates: &lt;input name=&quot;update_btn&quot; onclick=&quot;new Ajax.Updater({success:'succeed',failure:'fail'},
 #      '/testing/update', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)});
 #      return false;&quot; type=&quot;button&quot; value=&quot;Update&quot; /&gt;
 &lt;%= submit_to_remote 'update_btn', 'Update', :url =&gt; { :action =&gt; 'update' },
    :update =&gt; { :success =&gt; &quot;succeed&quot;, :failure =&gt; &quot;fail&quot; }
</pre>
<p>
<tt>options</tt> argument is the same as in <a
href="PrototypeHelper.html#M000960">form_remote_tag</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000963-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000963-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 412</span>
412:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">submit_to_remote</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span>, <span class="ruby-identifier">options</span> = {})
413:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:with</span>] <span class="ruby-operator">||=</span> <span class="ruby-value str">'Form.serialize(this.form)'</span>
414: 
415:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:html</span>] <span class="ruby-operator">||=</span> {}
416:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:html</span>][<span class="ruby-identifier">:type</span>] = <span class="ruby-value str">'button'</span>
417:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:html</span>][<span class="ruby-identifier">:onclick</span>] = <span class="ruby-node">&quot;#{remote_function(options)}; return false;&quot;</span>
418:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:html</span>][<span class="ruby-identifier">:name</span>] = <span class="ruby-identifier">name</span>
419:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:html</span>][<span class="ruby-identifier">:value</span>] = <span class="ruby-identifier">value</span>
420: 
421:         <span class="ruby-identifier">tag</span>(<span class="ruby-value str">&quot;input&quot;</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:html</span>], <span class="ruby-keyword kw">false</span>)
422:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000968" class="method-detail">
        <a name="M000968"></a>

        <div class="method-heading">
          <a href="#M000968" class="method-signature">
          <span class="method-name">update_page</span><span class="method-args">(&amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Yields a JavaScriptGenerator and returns the generated JavaScript code. Use
this to update multiple elements on a page in an Ajax response. See
JavaScriptGenerator for more information.
</p>
<p>
Example:
</p>
<pre>
  update_page do |page|
    page.hide 'spinner'
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000968-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000968-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 991</span>
991:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_page</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
992:         <span class="ruby-constant">JavaScriptGenerator</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@template</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>).<span class="ruby-identifier">to_s</span>
993:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000969" class="method-detail">
        <a name="M000969"></a>

        <div class="method-heading">
          <a href="#M000969" class="method-signature">
          <span class="method-name">update_page_tag</span><span class="method-args">(html_options = {}, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Works like <a href="PrototypeHelper.html#M000968">update_page</a> but wraps
the generated JavaScript in a &lt;script&gt; tag. Use this to include
generated JavaScript in an ERb template. See JavaScriptGenerator for more
information.
</p>
<p>
<tt>html_options</tt> may be a hash of &lt;script&gt; attributes to be
passed to <a
href="JavaScriptHelper.html#M001065">ActionView::Helpers::JavaScriptHelper#javascript_tag</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000969-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000969-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 1001</span>
1001:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_page_tag</span>(<span class="ruby-identifier">html_options</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1002:         <span class="ruby-identifier">javascript_tag</span> <span class="ruby-identifier">update_page</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>), <span class="ruby-identifier">html_options</span>
1003:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M000973" class="method-detail">
        <a name="M000973"></a>

        <div class="method-heading">
          <a href="#M000973" class="method-signature">
          <span class="method-name">build_callbacks</span><span class="method-args">(options)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000973-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000973-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 1055</span>
1055:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">build_callbacks</span>(<span class="ruby-identifier">options</span>)
1056:         <span class="ruby-identifier">callbacks</span> = {}
1057:         <span class="ruby-identifier">options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">callback</span>, <span class="ruby-identifier">code</span><span class="ruby-operator">|</span>
1058:           <span class="ruby-keyword kw">if</span> <span class="ruby-constant">CALLBACKS</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">callback</span>)
1059:             <span class="ruby-identifier">name</span> = <span class="ruby-value str">'on'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">callback</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">capitalize</span>
1060:             <span class="ruby-identifier">callbacks</span>[<span class="ruby-identifier">name</span>] = <span class="ruby-node">&quot;function(request){#{code}}&quot;</span>
1061:           <span class="ruby-keyword kw">end</span>
1062:         <span class="ruby-keyword kw">end</span>
1063:         <span class="ruby-identifier">callbacks</span>
1064:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000972" class="method-detail">
        <a name="M000972"></a>

        <div class="method-heading">
          <a href="#M000972" class="method-signature">
          <span class="method-name">build_observer</span><span class="method-args">(klass, name, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000972-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000972-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 1038</span>
1038:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">build_observer</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {})
1039:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:with</span>] <span class="ruby-operator">&amp;&amp;</span> (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:with</span>] <span class="ruby-operator">!~</span> <span class="ruby-regexp re">/[\{=(.]/</span>)
1040:           <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:with</span>] = <span class="ruby-node">&quot;'#{options[:with]}=' + value&quot;</span>
1041:         <span class="ruby-keyword kw">else</span>
1042:           <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:with</span>] <span class="ruby-operator">||=</span> <span class="ruby-value str">'value'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:function</span>]
1043:         <span class="ruby-keyword kw">end</span>
1044: 
1045:         <span class="ruby-identifier">callback</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:function</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">remote_function</span>(<span class="ruby-identifier">options</span>)
1046:         <span class="ruby-identifier">javascript</span>  = <span class="ruby-node">&quot;new #{klass}('#{name}', &quot;</span>
1047:         <span class="ruby-identifier">javascript</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{options[:frequency]}, &quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:frequency</span>]
1048:         <span class="ruby-identifier">javascript</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;function(element, value) {&quot;</span>
1049:         <span class="ruby-identifier">javascript</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{callback}}&quot;</span>
1050:         <span class="ruby-identifier">javascript</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;, '#{options[:on]}'&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:on</span>]
1051:         <span class="ruby-identifier">javascript</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;)&quot;</span>
1052:         <span class="ruby-identifier">javascript_tag</span>(<span class="ruby-identifier">javascript</span>)
1053:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000971" class="method-detail">
        <a name="M000971"></a>

        <div class="method-heading">
          <a href="#M000971" class="method-signature">
          <span class="method-name">method_option_to_s</span><span class="method-args">(method)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000971-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000971-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 1034</span>
1034:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">method_option_to_s</span>(<span class="ruby-identifier">method</span>) 
1035:         (<span class="ruby-identifier">method</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-operator">!</span><span class="ruby-identifier">method</span>.<span class="ruby-identifier">index</span>(<span class="ruby-value str">&quot;'&quot;</span>).<span class="ruby-identifier">nil?</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">method</span> <span class="ruby-operator">:</span> <span class="ruby-node">&quot;'#{method}'&quot;</span>
1036:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000970" class="method-detail">
        <a name="M000970"></a>

        <div class="method-heading">
          <a href="#M000970" class="method-signature">
          <span class="method-name">options_for_ajax</span><span class="method-args">(options)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000970-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000970-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb, line 1006</span>
1006:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_for_ajax</span>(<span class="ruby-identifier">options</span>)
1007:         <span class="ruby-identifier">js_options</span> = <span class="ruby-identifier">build_callbacks</span>(<span class="ruby-identifier">options</span>)
1008:       
1009:         <span class="ruby-identifier">js_options</span>[<span class="ruby-value str">'asynchronous'</span>] = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:type</span>] <span class="ruby-operator">!=</span> <span class="ruby-identifier">:synchronous</span>
1010:         <span class="ruby-identifier">js_options</span>[<span class="ruby-value str">'method'</span>]       = <span class="ruby-identifier">method_option_to_s</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:method</span>]) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:method</span>]
1011:         <span class="ruby-identifier">js_options</span>[<span class="ruby-value str">'insertion'</span>]    = <span class="ruby-node">&quot;Insertion.#{options[:position].to_s.camelize}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:position</span>]
1012:         <span class="ruby-identifier">js_options</span>[<span class="ruby-value str">'evalScripts'</span>]  = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:script</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:script</span>]
1013: 
1014:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:form</span>]
1015:           <span class="ruby-identifier">js_options</span>[<span class="ruby-value str">'parameters'</span>] = <span class="ruby-value str">'Form.serialize(this)'</span>
1016:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:submit</span>]
1017:           <span class="ruby-identifier">js_options</span>[<span class="ruby-value str">'parameters'</span>] = <span class="ruby-node">&quot;Form.serialize('#{options[:submit]}')&quot;</span>
1018:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:with</span>]
1019:           <span class="ruby-identifier">js_options</span>[<span class="ruby-value str">'parameters'</span>] = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:with</span>]
1020:         <span class="ruby-keyword kw">end</span>
1021:         
1022:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">protect_against_forgery?</span>
1023:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">js_options</span>[<span class="ruby-value str">'parameters'</span>]
1024:             <span class="ruby-identifier">js_options</span>[<span class="ruby-value str">'parameters'</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot; + '&amp;&quot;</span>
1025:           <span class="ruby-keyword kw">else</span>
1026:             <span class="ruby-identifier">js_options</span>[<span class="ruby-value str">'parameters'</span>] = <span class="ruby-value str">&quot;'&quot;</span>
1027:           <span class="ruby-keyword kw">end</span>
1028:           <span class="ruby-identifier">js_options</span>[<span class="ruby-value str">'parameters'</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{request_forgery_protection_token}=' + encodeURIComponent('#{escape_javascript form_authenticity_token}')&quot;</span>
1029:         <span class="ruby-keyword kw">end</span>
1030:       
1031:         <span class="ruby-identifier">options_for_javascript</span>(<span class="ruby-identifier">js_options</span>)
1032:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>